//
//  FKOrderDetailInfoCell.m
//  WanTao
//
//  Created by Macbook Pro on 2019/4/12.
//  Copyright © 2019 Macbook Pro. All rights reserved.
//

#import "FKOrderDetailInfoCell.h"
#import "FKOrder.h"

@interface FKOrderDetailInfoCell ()

@property (nonatomic, weak) UILabel *orderSnLabel;
@property (nonatomic, weak) UILabel *createTimeLabel;
@property (nonatomic, weak) UILabel *orderTimeLabel;
@property (nonatomic, weak) UILabel *payTypeLabel;
@property (nonatomic, weak) UILabel *sendTimeLabel;
@property (nonatomic, weak) UILabel *receiveTimeLabel;

@end

@implementation FKOrderDetailInfoCell

- (void)setupSubviews
{
    [super setupSubviews];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.clipsToBounds = true;
    
    NSArray *titles = @[@"订单编号", @"创建时间", @"下单时间", @"支付方式", @"发货时间", @"收货时间"];
    CGFloat margin = fk_adjustW(6);
    CGFloat labelH = fk_adjustW(22);
    CGFloat labelX = 12;
    CGFloat titleLabelW = [titles.firstObject sizeWithAttributes:@{NSFontAttributeName : fk_adjustFont(12)}].width;
    CGFloat valueLabelW = 240;
    CGFloat valueLabelX = labelX + titleLabelW + 8;
    for (NSInteger index = 0; index < titles.count; index++) {
        UILabel *titleLabel = [UILabel fk_labelWithFont:fk_adjustFont(12) textColor:fkColor666666 text:titles[index]];
        [self.contentView addSubview:titleLabel];
        
        CGFloat labelY = margin + index * labelH;
        titleLabel.frame = CGRectMake(labelX, labelY, titleLabelW, labelH);
        
        UILabel *valueLabel = [UILabel fk_labelWithFont:fk_adjustFont(12) textColor:fkColor666666];
        [self.contentView addSubview:valueLabel];
        valueLabel.tag = 10 + index;
        valueLabel.frame = CGRectMake(valueLabelX, labelY, valueLabelW, labelH);
    }
    self.orderSnLabel = [self.contentView viewWithTag:10];
    self.createTimeLabel = [self.contentView viewWithTag:11];
    self.orderTimeLabel = [self.contentView viewWithTag:12];
    self.payTypeLabel = [self.contentView viewWithTag:13];
    self.sendTimeLabel = [self.contentView viewWithTag:14];
    self.receiveTimeLabel = [self.contentView viewWithTag:15];
    
    UIButton *getOrderSnBtn = [UIButton fk_btnWithTarget:self action:@selector(getOrderSnClicked) font:fk_adjustFont(14) normalTitle:@"复制" normalTitleColor:fkColor666666 selectedTitle:nil selectedTitleColor:nil normalImg:nil selectedImg:nil bgImg:[UIImage imageNamed:@"bg_white"] selectedBgImg:nil];
    [self.contentView addSubview:getOrderSnBtn];
    [getOrderSnBtn fk_viewCornerRadius:5 borderWidth:0.8 borderColor:[UIColor lightGrayColor]];
    
    UIView *separator = [[UIView alloc] init];
    [self.contentView addSubview:separator];
    separator.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    UIButton *callBtn = [UIButton fk_btnWithTarget:self action:@selector(callBtnClicked) font:fk_adjustFont(14) normalTitle:@"拨打电话" normalTitleColor:fkColor666666 selectedTitle:nil selectedTitleColor:nil normalImg:[UIImage imageNamed:@"dial"] selectedImg:nil bgImg:[UIImage imageNamed:@"bg_white"] selectedBgImg:nil];
    [self.contentView addSubview:callBtn];
    callBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 6, 0, 0);
    
    [getOrderSnBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.offset(40);
        make.height.offset(24);
        make.right.offset(-12);
        make.centerY.equalTo(self.orderSnLabel);
    }];
    [callBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.offset(0);
        make.height.offset(fk_adjustW(45));
    }];
    [separator mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.height.offset(0.8);
        make.bottom.equalTo(callBtn.mas_top);
    }];
}

- (void)getOrderSnClicked
{
    UIPasteboard *board = [UIPasteboard generalPasteboard];
    FKOrder *model = self.data;
    board.string = model.order_sn;
    [SVProgressHUD showSuccessWithStatus:@"订单号复制成功"];
}



- (void)callBtnClicked
{
    if ([self.delegate respondsToSelector:@selector(orderDetailInfoCell:didClickedCallBtn:)]) {
        [self.delegate orderDetailInfoCell:self didClickedCallBtn:nil];
    }
}

- (void)setData:(id)data
{
    [super setData:data];
    
    if ([data isKindOfClass:[FKOrder class]]) {
        FKOrder *model = data;
        
        self.orderSnLabel.text = model.order_sn;
        self.createTimeLabel.text = model.addTime;
        self.orderTimeLabel.text = model.payTime;
        self.payTypeLabel.text = model.pay_type;
        self.sendTimeLabel.text = model.fahuoTime;
        self.receiveTimeLabel.text = model.shouhuoTime;
    }
}



@end
